package com.sghd.candy.module.skill.facade;

import com.sghd.candy.module.player.manager.Player;
import com.sghd.candy.module.player.service.PlayerService;
import com.sghd.candy.module.skill.service.PlayerSkillService;
import com.sghd.pojo.candy.skill.vo.SkillVo;
import com.sghd.pojo.fight.game.Result;
import com.sghd.pojo.fight.game.RsetSkillVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import static com.sghd.pojo.StaticConfig.RUN_MODE_RUNTIME;
import static com.sghd.pojo.StaticConfig.RUN_MODE_TEST;

/**
 * @author Allen
 * @date 2018/12/10
 */
@Component
public class SkillFacadeImpl implements SkillFacade {
    private static final Logger logger = LoggerFactory.getLogger(SkillFacade.class);
    @Value("${run.mode}")
    private int runMode;
    @Autowired
    PlayerSkillService playerSkillService;
    @Autowired
    private PlayerService playerService;
    @Override
    public Result<String> selectSkill(long playerId, int skillId) {
        return playerSkillService.selectFightSkill(playerService.load(playerId), skillId);
    }

    @Override
    public Result<String> removeSkill(long playerId, int skillId) {
        return playerSkillService.removeFightSkill(playerService.load(playerId), skillId);
    }

    @Override
    public SkillVo skillList(long playerId) {
        return playerSkillService.skillList(playerService.load(playerId));
    }

    @Override
    public Result<String> upgrade(long playerId, int skillId) {
        return playerSkillService.upgrade(playerId, skillId);
    }

    @Override
    public RsetSkillVo random(String ip, RsetSkillVo resetVo) {
        if (runMode == RUN_MODE_RUNTIME) {
            // 3次免费随机机会
            // 免费次数用完后，每次随机费用递增
            // 锁定个数，费用也是递增
            Player player = playerService.load(resetVo.getPlayerId());
            return playerSkillService.random(player, resetVo);
        }

        return resetVo.setResult(Result.SUCCESS());
    }
}
